# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=garage
pkgver=0.9.0
pkgrel=0
pkgdesc="Lightweight S3-compatible distributed object store"
url="https://garagehq.deuxfleurs.fr"
# armhf,armv7,x86: fails to build (std::bad_alloc)
# riscv64: would take eternity to build
# s390x: fails to build nix crate
arch="all !armhf !armv7 !x86 !riscv64 !s390x"
license="AGPL-3.0"
makedepends="
	cargo
	cargo-auditable
	libsodium-dev
	protoc
	sqlite-dev
	zstd-dev
	"
checkdepends="openssl-dev"
pkgusers="garage"
pkggroups="garage"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-openrc"
source="https://github.com/deuxfleurs-org/garage/archive/v$pkgver/garage-$pkgver.tar.gz
	syslog-support.patch
	garage.toml
	$pkgname.initd
	$pkgname.confd
	"

case "$CARCH" in
	# Fails to build ring crate.
	ppc64le | s390x) options="!check";;
esac

# Disable bundled-libs, metrics, sqlite, sled, k2v
_cargo_opts="--frozen --no-default-features --features lmdb,system-libs"

export CARGO_PROFILE_RELEASE_OPT_LEVEL=2

export SODIUM_USE_PKG_CONFIG=1
export GIT_VERSION="v$pkgver"  # version used in --version

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts --workspace
}

package() {
	install -D -m755 target/release/$pkgname -t "$pkgdir"/usr/bin/

	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -D -m640 -o garage -g garage "$srcdir"/garage.toml -t "$pkgdir"/etc/

	install -d -m700 -o garage -g garage "$pkgdir"/var/lib/$pkgname
}

sha512sums="
967a434aaae1c4d3c28c9c767f2da32f7e503b49a7eb8dc3ee27ecd4928952b13e454ca0dd18da4a48f1a843dbd8d073b3dc604e89225fcb7fe3570737e05442  garage-0.9.0.tar.gz
e59399ab8a16b591498be0d6510054adf14ff5c4ec15ddfdf69b046119fa036c8abef10173aa29f832ff64d1b0c46b51d17051a450d85b61bd99eb91b8c64ed5  syslog-support.patch
1a0c0c02aa41043274cb3f1dfeb2e2621e24c198e33ebf8ed15c9e0f63b4d4c43be680bc895cf55688ebfe751d71463255e956fdc070c28d85c400444a5589bb  garage.toml
a2130fa81ed2c8af266ed1e86d0c72e3aae6995599347e4488c6cd4cc83217fbb65ea9121415985f8cdcd15aaee9b28886b1ccf24755571b3ddf2fc5d8dd5b3a  garage.initd
f31bb5bde3ff41dc5fa6832c8ff24e1f1027b34513ab5e5c008df13495b53a569d3cb5adefed93cf780f5e488ff760603097785d85e1a884538e802e415205bd  garage.confd
"
